@inherits Microsoft.VisualStudio.Web.CodeGeneration.Templating.RazorTemplateBase
@using System.Collections.Generic
@using System.Linq
using System;
@{
    var namespaceSet = new HashSet<string>(
        new string[]
        {
            "Microsoft.AspNetCore.Identity",
            "Microsoft.AspNetCore.Identity.UI",
            "Microsoft.AspNetCore.Hosting",
            "Microsoft.EntityFrameworkCore",
            "Microsoft.Extensions.Configuration",
            "Microsoft.Extensions.DependencyInjection",
        });
    var thisNamespace = $"{Model.Namespace}.Areas.Identity";

    if (!string.IsNullOrEmpty(Model.UserClassNamespace) && thisNamespace != Model.UserClassNamespace)
    {
        namespaceSet.Add(Model.UserClassNamespace);
    }
    else
    {
        namespaceSet.Add("Microsoft.AspNetCore.Identity.EntityFrameworkCore");
    }
    if (thisNamespace != Model.DbContextNamespace)
    {
        namespaceSet.Add(Model.DbContextNamespace);
    }
    foreach(var name in namespaceSet.OrderBy(n => n))
    {
@:using @name;
    }
}

[assembly: HostingStartup(typeof(@(thisNamespace).IdentityHostingStartup))]
namespace @(thisNamespace)
{
    public class IdentityHostingStartup : IHostingStartup
    {
        public void Configure(IWebHostBuilder builder)
        {
@{
@:            builder.ConfigureServices((context, services) => {

    if (!Model.IsUsingExistingDbContext)
    {
        if (Model.UseSQLite)
        {
@:                services.AddDbContext<@Model.DbContextClass>(options =>
@:                    options.UseSqlite(
@:                        context.Configuration.GetConnectionString("@(Model.DbContextClass)Connection")));
        } // End if Model.UseSQLite
        else
        {
@:                services.AddDbContext<@Model.DbContextClass>(options =>
@:                    options.UseSqlServer(
@:                        context.Configuration.GetConnectionString("@(Model.DbContextClass)Connection")));
        } // End else
@:

@:                services.AddDefaultIdentity<@(Model.UserClass)>(options => options.SignIn.RequireConfirmedAccount = true)
@:                    .AddEntityFrameworkStores<@Model.DbContextClass>();

    } // End Model.IsUsingExstingDbContext

@:            });
        }
        }
    }
}